#include "junix.h"

void sigh(int signo)
{
	if( signo==SIGINT)
		printf("SIGINT handler\n");

	exit(1);
}

int main(int argc, char **argv)
{
	ssize_t len;
	char buf[BUFSIZ];

	/* 
	if( signal(SIGINT, SIG_IGN) == SIG_ERR)
		err_sys("signal");
	*/

	struct sigaction sa;
	memset( &sa, 0, sizeof(sa) );
	sa.sa_handler=sigh;
	sa.sa_flags=SA_RESTART;

	if( sigaction( SIGINT, &sa, NULL) == -1)
		err_sys("sigaction");

	sigset_t  mask;
	sigemptyset(&mask);
	sigaddset(&mask, SIGINT);

	if( sigprocmask(SIG_BLOCK, &mask, NULL) == -1)
		err_sys("sigprocmask");

	int fd=Open("FIFO",O_RDONLY);
	if( (len=read(fd,buf, BUFSIZ))==-1) 
		err_sys("read");

	sigemptyset(&mask);

	if ( sigpending( &mask) == -1)
		err_sys("sigpending");

	if( sigismember(&mask, SIGINT))
		printf("SIGINT pending\n");


	sigemptyset(&mask);
	sigaddset(&mask, SIGINT);
	if( sigprocmask(SIG_UNBLOCK, &mask, NULL) == -1)
		err_sys("sigprocmask");

	while(1)
	{ }

	Close(fd);
    exit(0);
}

